//
//  TestSDWebImageViewController.m
//  HYSmileiOS
//
//  Created by alekye on 16/5/1.
//  Copyright © 2016年 heyou. All rights reserved.
//

#import "TestSDWebImageViewController.h"
#import "heyou.h"

@interface TestSDWebImageViewController ()
- (IBAction)showGIF:(id)sender;
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;

@property (strong, nonatomic) UIImage *gifImage;
- (IBAction)stopGIF:(id)sender;
- (IBAction)onGesture:(id)sender;
- (IBAction)printCachePath:(id)sender;
- (IBAction)clearCache:(id)sender;

@end

@implementation TestSDWebImageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)showGIF:(id)sender {
//    NSString *sURL = @"http://106.187.52.9/wp-content/uploads/2012/07/006.gif";
    NSURL *tURL = [NSURL URLWithString:@"http://106.187.52.9/wp-content/uploads/2012/07/006.gif"];
    WS(ws);
    
//    BOOL isExist = [[SDImageCache sharedImageCache] diskImageExistsWithKey:sURL];
    
    UIImage *placeHolder = [UIImage imageNamed:@"test1"];
    
    //        [tCell.imageViewContent sd_setImageWithURL:tURL placeholderImage:placeHolder completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    //            NSLog(@"imageURL = %@", imageURL);
    //        }];
    [self.myImageView sd_setImageWithURL:tURL placeholderImage:placeHolder options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
        NSLog(@"receivedSize = %ld, expectedSize = %ld", receivedSize, expectedSize);
    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        NSLog(@"imageURL = %@", imageURL);
        ws.gifImage = image;
    }];
}
- (IBAction)stopGIF:(id)sender {
    if (self.gifImage) {
        NSArray<UIImage*> *ary = [self.gifImage images];
        UIImage *fImage = [ary firstObject];
        if (fImage) {
            self.myImageView.image = fImage;
        }
    }
}

- (IBAction)onGesture:(id)sender {
    [self.myImageView handleSingleTapWithBlock:^{
        NSLog(@"---------- tap");
        UIWindow* window = [UIApplication sharedApplication].keyWindow;
        
        UIView *view = [UIView new];
        CGRect windowFrame = window.bounds;
        view.frame = windowFrame;
        view.backgroundColor = [UIColor blackColor];
        view.alpha = 0.5f;
        
        [window addSubview:view];
    }];
    
    [self.myImageView handleDoubleTapWithBlock:^{
        NSLog(@"---------- tap ------ 2222");
    }];
}

- (IBAction)printCachePath:(id)sender {
    NSString *cachePath = [[SDImageCache sharedImageCache] defaultCachePathForKey:nil];
    NSLog(@"cachePath = %@", cachePath);
}

- (IBAction)clearCache:(id)sender {
    [[SDImageCache sharedImageCache] clearDisk];
}
@end
